package com.sunseagear.wind.modules.sys.entity.vo;

import com.sunseagear.wind.modules.sys.entity.Menu;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MenuVo extends HashMap<String, Object> {

    public MenuVo(Menu menu) {
        putObject(menu);
    }

    //设置节点
    public MenuVo putObject(Menu menu) {
        put("id", menu.getId());
        put("name", menu.getId());
        put("path", menu.getPath());
        put("component", menu.getComponent());
        put("type", menu.getType());
        put("hidden", !menu.isEnable());
        put("parentId", menu.getParentId());

        //设置meta
        Map<String, Object> meta = new HashMap<>();
        meta.put("title", menu.getName());
        meta.put("icon", menu.getIcon());
        meta.put("card", menu.getCard());
        meta.put("permission", menu.getPermission());
        meta.put("isCache", menu.getIsCache());
        put("meta", meta);
        return this;
    }

    public List<MenuVo> getChildren() {
        if (!containsKey("children")) {
            put("children", new ArrayList<MenuVo>());
        }
        return (List<MenuVo>) get("children");
    }
}
